Enable warn_unreachable for mypy self-check#18523
Conversation
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
Do you have some specific items in mind? I can surely add asserts where needed. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I actually just did this too! I ended up with quite a few Though that branch also passes mypy's test suite, so maybe that's a sign that actually those asserts aren't necessary at all and mypy was correct. |
There was a problem hiding this comment.
I'm generally unsure about the isinstance(x, FuncBase) changes where x: Node (and similar mypy_extensions.trait workarounds) because it seems like that just uses tuples to work around reachability? I haven't tried some testcases locally so I'm not entirely sure though.
| assert sys.platform == "win32" | ||
| if sys.platform == "win32": | ||
| assert sys.platform == "win32", "Running not on Windows" | ||
| if sys.platform == "win32": # needed to find win specific sys apis |
There was a problem hiding this comment.
Nope, sadly I can't :(
Looks like that mypy does not narrow sys.platform after assert (this might be a bug).
There was a problem hiding this comment.
But, I added assert False in the end instead, it is more readable now.
There was a problem hiding this comment.
Nope, sadly I can't :( Looks like that mypy does not narrow
sys.platformafterassert(this might be a bug).
Huh I was able to. But I guess that might just be because I was testing on Windows.
There was a problem hiding this comment.
Yes, you need to set platform = win32 or platform = linux manually in .ini file for that.
Sorry, I don't understand your question. Can you please provide an example? |
This comment has been minimized.
This comment has been minimized.
I was confused, actually. I've now read the docstring of IMO we should fix the issue at hand but continuing with (3) is OK as long as you update the comment around |
This comment has been minimized.
This comment has been minimized.
|
I will leave this open for a couple of days to give an opportunity for second rounds of reviewes, and merge on Wen or so :) Thanks, @A5rocks! |
|
|
||
|
|
||
| def normalize_path_separators(path: str) -> str: | ||
| if sys.platform == "win32": |
There was a problem hiding this comment.
If #18539 or a similar fix is merged, then this change should no longer be necessary I believe.
This comment has been minimized.
This comment has been minimized.
|
Going to merge #18523 later tomorrow, if no one objects |
|
Diff from mypy_primer, showing the effect of this PR on open source code: freqtrade (https://github.com/freqtrade/freqtrade): 1.95x slower (129.1s -> 252.2s in a single noisy sample)
|
This check prooved to be useful, since it find a lot of dead / incorrect code. Closes python#18079 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This check prooved to be useful, since it find a lot of dead / incorrect code.
Closes #18079